package com.hafu.view;
import com.hafu.service.UserService;
import com.hafu.util.StringUtil;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout;
public class LoginFrm extends JFrame {
    private UserService userService = new UserService();
    public LoginFrm() {
        initComponents();
    }
    private void button1(ActionEvent e) {
        String username = textField1.getText();
        String password = new String(passwordField1.getPassword());
        if (StringUtil.isEmpty(username)) {
            JOptionPane.showMessageDialog(null, "用户名不能为空");
            return;
        }
        if (StringUtil.isEmpty(password)) {
            JOptionPane.showMessageDialog(null, "密码不能为空");
            return;
        }
        Boolean isLogin = userService.isLogin(username, password);
        if (isLogin) {
            JOptionPane.showMessageDialog(null, "登录成功");
            this.dispose();
            MainFrm mainFrm = new MainFrm();
            mainFrm.setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "用户名或密码错误");
        }
    }
    private void initComponents() {
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        textField1 = new JTextField();
        passwordField1 = new JPasswordField();
        button1 = new JButton();
        setResizable(false);
        Container contentPane = getContentPane();
        label1.setText("\u6cb3\u5357\u8d22\u653f\u91d1\u878d\u5b66\u9662\u6c34\u679c\u8fdb\u9500\u5b58\u7cfb\u7edf");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getStyle() | Font.BOLD, label1.getFont().getSize() + 7f));
        label2.setText("\u7528\u6237\u540d");
        label3.setText("\u5bc6\u7801");
        button1.setText("\u767b\u5f55");
        button1.addActionListener(e -> button1(e));
        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
                contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                                .addGroup(contentPaneLayout.createParallelGroup()
                                        .addGroup(contentPaneLayout.createSequentialGroup()
                                                .addGap(179, 179, 179)
                                                .addGroup(contentPaneLayout.createParallelGroup()
                                                        .addGroup(contentPaneLayout.createSequentialGroup()
                                                                .addGroup(contentPaneLayout.createParallelGroup()
                                                                        .addComponent(label2, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
                                                                        .addComponent(label3))
                                                                .addGap(37, 37, 37)
                                                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                                        .addComponent(textField1)
                                                                        .addComponent(passwordField1, GroupLayout.PREFERRED_SIZE, 215, GroupLayout.PREFERRED_SIZE)))
                                                        .addComponent(label1, GroupLayout.PREFERRED_SIZE, 330, GroupLayout.PREFERRED_SIZE)))
                                        .addGroup(contentPaneLayout.createSequentialGroup()
                                                .addGap(261, 261, 261)
                                                .addComponent(button1, GroupLayout.PREFERRED_SIZE, 157, GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(219, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
                contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                                .addGap(82, 82, 82)
                                .addComponent(label1)
                                .addGap(84, 84, 84)
                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label2)
                                        .addComponent(textField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addGap(46, 46, 46)
                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label3)
                                        .addComponent(passwordField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
                                .addComponent(button1)
                                .addGap(50, 50, 50))
        );
        pack();
        setLocationRelativeTo(getOwner());
    }
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JTextField textField1;
    private JPasswordField passwordField1;
    private JButton button1;
}